<template>
  <div class="app-container">
    <div class="search-bar">
      <el-form ref="form" :model="searchData" label-width="80px" size="mini">
        <el-row :gutter="10">
          <el-col :span="3.5">
            <el-form-item label="作业区">
              <el-select
                v-model="searchData.alarm_area"
                clearable
                placeholder="请选择作业区"
                style="width: 130px"
              >
                <el-option
                  v-for="(item, i) in opeArea"
                  :key="i"
                  :label="item"
                  :value="item"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3.5">
            <el-form-item label="预警状态">
              <el-select
                v-model="searchData.alarm_cyclestate"
                clearable
                placeholder="请选择预警状态"
                style="width: 130px"
              >
                <el-option label="已预警" value="0" />
                <el-option label="取消预警" value="1" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3.5">
            <el-form-item label="起始日期">
              <el-date-picker
                v-model="searchData.start_time"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
                style="width: 130px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="3.5">
            <el-form-item label="截止日期">
              <el-date-picker
                v-model="searchData.end_time"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
                style="width: 130px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="">
              <el-button
                type="primary"
                size="mini"
                @click="search"
              >查 询</el-button>
              <el-button size="mini" @click="reset">清 空</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="content">
      <el-table
        :data="tableData"
        height="700"
        border
        :header-cell-style="{height:'30px',padding:'0px',fontSize:'14px'}"
        style="width: 100%;font-size: 13px"
        :row-style="{height:'20px'}"
        :cell-style="{padding:'1px'}"
      >
        <el-table-column type="index" width="50"/>
        <el-table-column
          prop="alarm_wellname"
          label="井号"
          sortable
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_area"
          sortable
          label="单位"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_org"
          label="站号"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_block"
          label="区块"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_strata"
          label="层位"
          header-align="center"
          align="center"
        />
        <el-table-column label="生产情况" header-align="center">
          <el-table-column
            prop="alarm_fluidvolume"
            label="液量"
            sortable
            header-align="center"
            align="center"
          />
          <el-table-column
            prop="alarm_oilvolume"
            label="油量"
            sortable
            header-align="center"
            align="center"
          />
          <el-table-column
            prop="alarm_watervolume"
            label="含水"
            sortable
            header-align="center"
            align="center"
          />
        </el-table-column>
        <el-table-column
          prop="alarm_pumpdepth"
          label="泵挂深度"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_cleancycle"
          label="清蜡周期"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_craft"
          label="清蜡工艺"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            {{
              scope.row.alarm_craft == '1'
                ? '热洗'
                : scope.row.alarm_craft == '2'
                  ? '化防'
                  : scope.row.alarm_craft == '3'
                    ? '化防+热洗'
                    : '冷洗'
            }}
          </template>
        </el-table-column>
        <el-table-column
          prop="alarm_hotwashamount"
          label="热洗用液"
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_plancleandate"
          label="清防蜡计划日期"
          sortable
          header-align="center"
          align="center"
        />
        <el-table-column
          prop="alarm_reason"
          label="预警原因"
          header-align="center"
          align="center"
        />
      </el-table>
      <Pagination
        :page.sync="page"
        :limit.sync="limit"
        :total="total"
        @changePage="getListPage1(arguments)"
        @size-change="handleSizeChange"
      />
    </div>
  </div>
</template>

<script>
import Pagination from '@/components/pagination.vue'
export default {
  components: { Pagination },
  data() {
    return {
      searchData: {
        alarm_class_array: ['0'],
        alarm_area: '',
        alarm_cyclestate: '0',
        start_time: '',
        end_time: ''
      },
      tableData: [],
      opeArea:['第一采油作业区','第二采油作业区', '第三采油作业区','第五采油作业区','第七采油作业区','第八采油作业区','第九采油作业区','运行维护一中心'],
      page: 1,
      limit: 20,
      total: 0
    }
  },
  created() {
    this.getListPage(this.page, this.limit, this.searchData)
  },
  methods: {
    getListPage(pageNum, pageSize, data) {
      this.$http
        .post('/TAlarmWell/pageQuery', {
          pageNum,
          pageSize,
          data
        })
        .then(({ data: { data: res }}) => {
          console.log(res)
          this.tableData = res.records
          this.total = res.total
        })
        .catch((err) => {
          console.log(err)
          this.$message.error(err)
        })
    },
    //页码变动
    getListPage1(msg){
      let pageNum=msg[0]
      let pageSize=msg[1]
      let data=this.searchData
      this.$http.post('/TAlarmWell/pageQuery', { pageSize, pageNum, data }).then(({ data: { data: res }}) => {
        this.tableData = res.records
        this.total = res.total
      })
    },
    //每页记录数变动
    handleSizeChange(size){
      let pageSize=this.page
      let pageNum=size
      let data=this.searchData
      this.$http.post('/TAlarmWell/pageQuery', { pageSize, pageNum, data }).then(({ data: { data: res }}) => {
        this.tableData = res.records
        this.total = res.total
      })
    },
    changePage(pageNum, pageSize) {
      this.getListPage(pageNum, pageSize, this.searchData)
    },
    search() {
      this.page = 1
      this.getListPage(this.page, this.limit, this.searchData)
    },
    reset() {
      this.searchData = {
        alarm_class_array: ['0']
      }
    }
  }
}
</script>

<style scoped>
</style>
